Maintains a table of instances.
@ivar instances: mapping of index to controller instance
- @type instances: {int: Controller}
+ @type instances: {String: Controller}
@ivar dom: domain
@type dom: int
"""
def getInstanceByDom(self, dom):
"""Get the controller instance for the given domain.
+
+ @param dom: domain id
+ @type dom: int
+ @return: controller or None
"""
for inst in self.instances.values():
if inst.dom == dom:
return None
def delInstance(self, instance):
- """Delete an instance from the table.
+ """Delete a controller instance from the table.
+
+ @param instance: controller instance
"""
if instance.idx in self.instances:
del self.instances[instance.idx]
@type dom: int
@param recreate: true if the instance is being recreated (after xend restart)
@type recreate: int
+ @return: controller instance
+ @rtype: Controller (or subclass)
"""
raise NotImplementedError()
def instanceClosed(self, instance):
"""Callback called when an instance is closed (usually by the instance).
+
+ @param instance: controller instance
"""
self.delInstance(instance)
class Controller(CtrlMsgRcvr):
"""Abstract class for a device controller attached to a domain.
+
+ @ivar factory: controller factory
+ @type factory: ControllerFactory
+ @ivar dom: domain
+ @type dom: int
+ @ivar channel: channel to the domain
+ @type channel: Channel
+ @ivar idx: channel index
+ @type idx: String
"""
def __init__(self, factory, dom):
class Dev:
"""Abstract class for a device attached to a device controller.
+
+ @ivar idx: identifier
+ @type idx: String
+ @ivar controller: device controller
+ @type controller: DeviceController
+ @ivar props: property table
+ @type props: { String: value }
"""
def __init__(self, idx, controller):
del self.props[k]
def sxpr(self):
+ """Get the s-expression for the deivice.
+ Implement in a subclass.
+
+ @return: sxpr
+ """
raise NotImplementedError()
# Copyright (C) 2004 Mike Wray <mike.wray@hp.com>
+"""Support for virtual network interfaces.
+"""
import random
self.majorTypes = [ CMSG_NETIF_BE ]
self.subTypes = {
- #CMSG_NETIF_BE_CREATE : self.recv_be_create,
- #CMSG_NETIF_BE_CONNECT: self.recv_be_connect,
CMSG_NETIF_BE_DRIVER_STATUS_CHANGED: self.recv_be_driver_status_changed,
}
self.attached = 1
def createInstance(self, dom, recreate=0):
"""Create or find the network interface controller for a domain.
- dom domain
- recreate if true this is a recreate (xend restarted)
-
- returns netif controller
+ @param dom: domain
+ @param recreate: if true this is a recreate (xend restarted)
+ @return: netif controller
"""
netif = self.getInstanceByDom(dom)
if netif is None:
def getDomainDevices(self, dom):
"""Get the network device controllers for a domain.
- dom domain
-
- returns netif controller
+ @param dom: domain
+ @return: netif controller list
"""
netif = self.getInstanceByDom(dom)
return (netif and netif.getDevices()) or []
def getDomainDevice(self, dom, vif):
"""Get a virtual network interface device for a domain.
- dom domain
- vif virtual interface index
-
- returns NetDev
+ @param dom: domain
+ @param vif: virtual interface index
+ @return: NetDev
"""
netif = self.getInstanceByDom(dom)
return (netif and netif.getDevice(vif)) or None
def setControlDomain(self, dom, recreate=0):
"""Set the 'back-end' device driver domain.
- dom domain
- recreate if true this is a recreate (xend restarted)
+ @param dom: domain
+ @param recreate: if true this is a recreate (xend restarted)
"""
if self.dom == dom: return
self.deregisterChannel()
def getControlDomain(self):
"""Get the domain id of the back-end control domain.
+
+ @return domain id
"""
return self.dom
if netif:
netif.send_interface_connected(vif)
else:
- log.warning("respond_be_connect> unknown dom=%d vif=%d", dom, vif)
+ log.warning("respond_be_connect> unknown vif dom=%d vif=%d", dom, vif)
pass
def recv_be_driver_status_changed(self, msg, req):
return ':'.join(map(lambda x: "%02x" % x, self.mac))
def vifctl_params(self, vmname=None):
+ """Get the parameters to pass to vifctl.
+ """
dom = self.controller.dom
if vmname is None:
xd = get_component('xen.xend.XendDomain')
def vifctl(self, op, vmname=None):
"""Bring the device up or down.
+ The vmname is needed when bringing a device up for a new domain because
+ the domain is not yet in the table so we can't look its name up.
+
+ @param op: operation name (up, down)
+ @param vmname: vmname
"""
Vifctl.vifctl(op, **self.vifctl_params(vmname=vmname))
vnet = XendVnet.instance().vnet_of_bridge(self.bridge)
def getDevice(self, vif):
"""Get a device.
- vif device index
-
- returns device (or None)
+ @param vif: device index
+ @return: device (or None)
"""
return self.devices.get(vif)
def addDevice(self, vif, config):
"""Add a network interface.
- vif device index
- config device configuration
-
- returns device
+ @param vif: device index
+ @param config: device configuration
+ @return: device
"""
dev = NetDev(self, vif, config)
self.devices[vif] = dev
self.destroyDevices()
def destroyDevices(self):
+ """Destroy all devices.
+ """
for dev in self.getDevices():
dev.destroy()
def attachDevice(self, vif, config, recreate=0):
"""Attach a network device.
- If vmac is None a random mac address is assigned.
- @param vif interface index
- @param vmac mac address (string)
+ @param vif: interface index
+ @param config: device configuration
+ @param recreate: recreate flag (true after xend restart)
+ @return: deferred
"""
self.addDevice(vif, config)
d = defer.Deferred()